package com.design.dynamic;

import org.springframework.expression.IndexAccessor;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 通用日志处理器
 */
public class LoggerInvoicationHandle implements InvocationHandler {
    private Object target;

    public LoggerInvoicationHandle(Object target){
        this.target=target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long start = System.currentTimeMillis();
        String methodName = method.getName();
        System.out.println("开始执行方法:"+methodName);
        Object result = method.invoke(target, args);
        long end = System.currentTimeMillis();
        System.out.println("方法执行结束:"+methodName+"，耗时:"+(end-start));
        return result;
    }
}
